<?php

/**
 * Load parameter from GET
 * @param String $name name of the parameter
 * @param mixed $default_value
 */
function request_get($name,$default_value=null) {
	$ret = $default_value;
	
	if(isset($_GET[$name])) {
		$ret = $_GET[$name];
	}
	
	return $ret;
}

/**
 * Load parameter from POST
 * @param String $name nome do parametro
 * @param mixed $default_value valor default quando este parametro não for setado
 */
function request_post($name,$default_value=null) {
	$ret = $default_value;
	
	if(isset($_POST[$name])) {
		$ret = $_POST[$name];
	}
	return $ret;
}

/**
 * Load parameter from GET or POST
 * @param String $name 
 * @param mixed $default_value deafult value when that is not setted 
 */
function request_param($name,$default_value=null) {
	$ret = $default_value;
	$val = null;
	
	if($val = request_get($name,null)) {
		$ret = $val;
	} else if($val = request_post($name,null)) {
		$ret = $val;
	}
	
	return $ret;
}

/**
 * Try to load a parameter from POST, if that is not a PHP true value throws an Exception
 * @param String $name 
 * @throws Exception - when the value is not a True PHP value (0,'',array()) 
 */
function request_required_post($name) {
	$ret = request_post($name);
	
	if($ret) {
		return $ret;
	}
	
	throw new Exception("Parâmetro {$name} obrigatório");
}

/**
 * Try to load a parameter from GET, if that is not a PHP true value throws an Exception
 * @param String $name 
 * @throws Exception - when the value is not a True PHP value (0,'',array()) 
 */
function request_required_get($name) {
	$ret = request_post($name);
	
	if($ret) {
		return $ret;
	}
	
	
	throw new Exception("Required parameter called {$name} was not sent");
}

/**
 * Try to load a parameter from GET or POST, if that is not a PHP true value throws an Exception
 * @param String $name 
 * @throws Exception - when the value is not a True PHP value (0,'',array()) 
 */
function request_required_param($name) {
	$ret = request_param($name);
	
	if($ret) {
		return $ret;
	}
	
	
	throw new Exception("Required parameter called {$name} was not sent");
}



?>